<?php

namespace app\models;

use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\GuideFieldData;

/**
 * GuideFieldDataQuery represents the model behind the search form of `app\models\GuideFieldData`.
 */
class GuideFieldDataQuery extends GuideFieldData
{
    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['gid', 'parent', 'flag', 'sound_body__target_id', 'sound_body__display', 'picture__target_id', 'picture__width', 'picture__height', 'list_picture__target_id', 'list_picture__width', 'list_picture__height', 'promote', 'map_zoom', 'ground_overlay__target_id', 'ground_overlay__width', 'ground_overlay__height', 'show_point', 'show_nav', 'show_label', 'uid', 'status', 'created', 'changed', 'default_langcode', 'content_translation_outdated', 'content_translation_uid'], 'integer'],
            [['type', 'langcode', 'title', 'subtitle', 'body__value', 'body__summary', 'body__format', 'sound_body__description', 'route_body__value', 'route_body__summary', 'route_body__format', 'picture__alt', 'picture__title', 'list_picture__alt', 'list_picture__title', 'ground_overlay__alt', 'ground_overlay__title', 'content_translation_source'], 'safe'],
            [['longitude', 'latitude', 'ground_overlay_east', 'ground_overlay_north', 'ground_overlay_west', 'ground_overlay_south'], 'number'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = GuideFieldData::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'gid' => $this->gid,
            'parent' => $this->parent,
            'flag' => $this->flag,
            'sound_body__target_id' => $this->sound_body__target_id,
            'sound_body__display' => $this->sound_body__display,
            'picture__target_id' => $this->picture__target_id,
            'picture__width' => $this->picture__width,
            'picture__height' => $this->picture__height,
            'list_picture__target_id' => $this->list_picture__target_id,
            'list_picture__width' => $this->list_picture__width,
            'list_picture__height' => $this->list_picture__height,
            'promote' => $this->promote,
            'longitude' => $this->longitude,
            'latitude' => $this->latitude,
            'map_zoom' => $this->map_zoom,
            'ground_overlay__target_id' => $this->ground_overlay__target_id,
            'ground_overlay__width' => $this->ground_overlay__width,
            'ground_overlay__height' => $this->ground_overlay__height,
            'ground_overlay_east' => $this->ground_overlay_east,
            'ground_overlay_north' => $this->ground_overlay_north,
            'ground_overlay_west' => $this->ground_overlay_west,
            'ground_overlay_south' => $this->ground_overlay_south,
            'show_point' => $this->show_point,
            'show_nav' => $this->show_nav,
            'show_label' => $this->show_label,
            'uid' => $this->uid,
            'status' => $this->status,
            'created' => $this->created,
            'changed' => $this->changed,
            'default_langcode' => $this->default_langcode,
            'content_translation_outdated' => $this->content_translation_outdated,
            'content_translation_uid' => $this->content_translation_uid,
        ]);

        $query->andFilterWhere(['like', 'type', $this->type])
            ->andFilterWhere(['like', 'langcode', $this->langcode])
            ->andFilterWhere(['like', 'title', $this->title])
            ->andFilterWhere(['like', 'subtitle', $this->subtitle])
            ->andFilterWhere(['like', 'body__value', $this->body__value])
            ->andFilterWhere(['like', 'body__summary', $this->body__summary])
            ->andFilterWhere(['like', 'body__format', $this->body__format])
            ->andFilterWhere(['like', 'sound_body__description', $this->sound_body__description])
            ->andFilterWhere(['like', 'route_body__value', $this->route_body__value])
            ->andFilterWhere(['like', 'route_body__summary', $this->route_body__summary])
            ->andFilterWhere(['like', 'route_body__format', $this->route_body__format])
            ->andFilterWhere(['like', 'picture__alt', $this->picture__alt])
            ->andFilterWhere(['like', 'picture__title', $this->picture__title])
            ->andFilterWhere(['like', 'list_picture__alt', $this->list_picture__alt])
            ->andFilterWhere(['like', 'list_picture__title', $this->list_picture__title])
            ->andFilterWhere(['like', 'ground_overlay__alt', $this->ground_overlay__alt])
            ->andFilterWhere(['like', 'ground_overlay__title', $this->ground_overlay__title])
            ->andFilterWhere(['like', 'content_translation_source', $this->content_translation_source]);

        return $dataProvider;
    }
}
